home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best of MacTutor - S…e Code for Volumes 1 to 5
/
The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin
/
Source Code
/
#26 (Nov 87)
/
asm lab Formatter
/
FormatDemo.asm
< prev
next >
Wrap
Assembly Source File
|
1987-10-22
|
6KB
|
280 lines
; FormatDemo.asm
;----------------
; Written by Mike™ Scanlin 1 JAN 1987
; Slightly modified by D. Smith
; for MacTutor. 19 OCT 1987
; driver program to demonstrate DrawNumsInAString
Include Traps.D
Include ToolEqu.D
Xref DrawNumsInAString
;Quickdraw Equates Used:
srcCopy EQU 0 ;copybits mode
portBits EQU $2 ;port's bitmap [bitmap]
portRect EQU $10 ;port's rectangle
FormatDemo:
PEA -4(A5) ;init everything
_InitGraf ;graf port
_InitFonts ;fonts
_InitWindows ;windows
_InitMenus ;menus
PEA Quit ;resume routine
_InitDialogs ;dialogs
_TEInit ;text edit
MOVE.L #$FFFF,D0
_FlushEvents ;clear event queque
_InitCursor ;cursor
CLR.L -(SP) ;returned menu handle
MOVE.W #1,-(SP) ;menu ID 1
_GetRMenu ;get resource menu
MOVE.L (SP), AppleHandle(A5) ;save menu handle
MOVE.L (SP), -(SP) ;put back on stack
CLR.W -(SP) ;add to menu end
_InsertMenu ;apple menu added
MOVE.L #'DRVR', -(SP) ;get das
_AddResMenu ;add das to menu
CLR.L -(SP) ;ret menu handle
MOVE.W #2, -(SP) ;menu ID 2
_GetRMenu ;get resource menu
CLR.W -(SP) ;add to end
_InsertMenu ;file menu
CLR.L -(SP) ;ret menu handle
MOVE.W #3, -(SP) ;menu ID 3
_GetRMenu ;get resource menu
CLR.W -(SP) ;add to end
_InsertMenu ;message menu
_DrawMenuBar ;do menu bar
CLR.L -(SP) ;return window ptr
CLR.L -(SP) ;heap window record
PEA wRect ;default rect size
PEA wTitle ;default tile
MOVE #$100,-(SP) ;true for visible
MOVE #noGrowDocProc,-(SP) ;window type
MOVE.L #-1,-(SP) ;window in front
CLR -(SP) ;no close box
MOVE.L #3,-(SP) ;reference value
_NewWindow ;make heap window
MOVE.L (SP),wPointer(A5) ;save window ptr
_SetPort ;set graf port to window
_PenNormal ;init pen
MOVE #4,-(SP) ;any mono-spaced font will do
_TextFont ;font
MOVE #0,-(SP) ;normal
_TextFace ;style
MOVE #12,-(SP) ;12 point type
_TextSize ;size
MOVE.L wPointer(A5), A0
PEA portRect(A0)
_ClipRect ;set clip region
GetEvent:
_SystemTask ;check das
CLR -(SP) ;returned event
MOVE #-1,-(SP) ;mask all events
PEA EventRecord(A5) ;event record
_GetNextEvent ;get next event
MOVE (SP)+,D0 ;pop result
BEQ.S GetEvent ;0=null event
MOVE What(A5),D0 ;what event?
CMPI #1,D0 ;mouseDown event?
BNE.S GetEvent ;no, try again
;handle a mouse down event
CLR -(SP) ;yes, where mouse?
MOVE.L Where(A5),-(SP)
PEA fndWindow(A5)
_FindWindow ;find window
MOVE (SP)+,D0 ;pop result
CMPI #1,D0 ;in menu bar?
BEQ MenuBar ;check quit
CMPI #2,D0 ;in system window?
BEQ System ;do sysem stuff
CMPI #4,D0 ;drag region?
BEQ DragIt ;do drag
CMPI #3,D0 ;content region?
BNE.S GetEvent ;no, ignore it
;do content click
CLR.L -(SP) ;yes, do click
_FrontWindow ;window up?
MOVE.L (SP)+, D0 ;pop result
CMP.L wPointer(A5), D0 ;our window up?
BEQ DoIt ;yes, do click
MOVE.L wPointer(A5), -(SP) ;no, activate
_SelectWindow ;make it front
MOVE.L wPointer(A5), -(SP)
_SetPort ;point grafport to it
BRA GetEvent ;get next click
DoIt:
;draw 10 strings in the window
MOVE.L wPointer(A5), A0
PEA portRect(A0) ;get wind port rect
_EraseRect ;erase port rect
MOVE #30,vPos(A5) ;set pen coord
;do 5 addition problems
MOVE #5,count(A5) ;5 problems count
@1 MOVE #56,-(SP) ;set pen coord
MOVE vPos(A5),-(SP)
_MoveTo ;move pen
CLR -(SP) ;get 1st operand
_Random ;a random number
MOVE (SP)+,D3 ;pop result
EXT.L D3
CLR -(SP) ;get 2nd operand
_Random ;a random number
MOVE (SP)+,D4 ;pop result
EXT.L D4
MOVE.L D3,D0
ADD.L D4,D0 ;addition problem
MOVE.L D0,-(SP) ;push result
MOVE.L D4,-(SP) ;push 2nd param
MOVE.L D3,-(SP) ;push 1st param
PEA FormatString2
JSR DrawNumsInAString ;format numbers
ADD #20,vPos(A5) ;reposition pen
SUB #1,count(A5) ;dec count
BNE @1 ;do next problem
;do 5 division problems
MOVE #5,count(A5) ;count
@3 MOVE #35,-(SP) ;pen position
MOVE vPos(A5),-(SP) ;pen position
_MoveTo ;set pen
CLR -(SP) ;get 20 bit random #
_Random
CLR -(SP)
_Random
MOVE.L (SP)+,D3
ANDI.L #$FFFFF,D3
@2 CLR -(SP) ;get 16 bit random #
_Random
MOVE (SP)+,D1
BEQ.S @2 ;don't divide by zero
MOVE.L D3,D0
DIVS D1,D0 ;do division problem
MOVE.L D0,-(SP) ;push fixed point result
MOVE D1,-(SP)
EXT.L D1
MOVE.L D1,-(SP) ;push 2nd longint
MOVE.L D3,-(SP) ;push 1st longint
PEA FormatString1
JSR DrawNumsInAString
ADD #20,vPos(A5)
SUB #1,count(A5)
BNE @3
JSR DoPic ;create quickdraw pic
BRA GetEvent
DragIt:
MOVE.L wPointer(A5), -(SP) ;window ptr
MOVE.L where(A5), -(SP) ;mouse
PEA dragbounds ;bounds
_DragWindow ;drag it
BRA GetEvent
System:
PEA EventRecord(A5)
MOVE.L fndWindow(A5), -(SP)
_SystemClick ;support das
BRA GetEvent
MenuBar:
CLR.L -(SP) ;menu choice
MOVE.L Where(A5), -(SP)
_MenuSelect
MOVE.W (SP)+,D5 ;menu
MOVE.W (SP)+,D6 ;item
CLR.W -(SP)
_HiLiteMenu
CMP #1,D5
BEQ AppleMenu
CMP #2,D5
BEQ FileMenu
BRA GetEvent
AppleMenu:
CMP #1,D6
BEQ About
PEA grafporttemp(A5) ;do das
_GetPort
Move.L AppleHandle(A5), -(SP)
Move.W D6,-(SP)
PEA DeskName(A5)
_GetItem ;get da name
CLR -(SP)
PEA DeskName(A5)
_OpenDeskAcc ;start up da
Move (SP)+, D0 ;result
MOVE.L grafporttemp(A5), -(SP)
_SetPort
BRA GetEvent
About:
Move.W #5, -(SP)
_SysBeep ;sorry charlie!
BRA GetEvent
FileMenu:
Quit:
_ExitToShell
DoPic:
CLR.L -(SP) ;save pic of screen
MOVE.L wPointer(A5), -(SP)
_GetWindowPic ;get current pic
MOVE.L (SP)+, A0
MOVE.L A0, -(SP)
_KillPicture ;kill it
CLR.L -(SP)
MOVE.L wPointer(A5), A0
PEA portRect(A0)
_OpenPicture ;open new pic
MOVE.L (SP)+, A0
MOVE.L wPointer(A5), -(SP)
MOVE.L A0, -(SP)
_SetWindowPic ;set in window rec
MOVE.L wPointer(A5), A0
PEA portBits(A0) ;set up copybits
PEA portBits(A0)
PEA portRect(A0)
PEA portRect(A0)
MOVE.W #srcCopy, -(SP)
CLR.L -(SP)
_CopyBits ;copy screen to pic
_ClosePicture ;close pic
rts
; Data structures - Constants
wRect DC 60,80,300,420
dragbounds DC 20,40,330,492
wTitle DC.B 17,'Formatted Numbers'
;note: format strings must end with a zero byte
FormatString1 DC.B '\i,10 / \i,7 = \f,7.5',0
FormatString2 DC.B '\i,7 + \i,7 = \i,7',0,0
; Data structures - variables
vPos DS 1
count DS 1
wPointer DS.L 1
fndWindow DS.L 1
AppleHandle DS.L 1
DeskName DS.L 1
grafporttemp DS.L 1
EventRecord DS.W 0
What DS.W 1
Message DS.L 1
When DS.L 1
Where DS.L 1
Modifiers DS.W 1